<template>
<div class="empty-cache views-container">
  <div class="main">
    <div class="pos-center">
      <div class="flex-col flex-align-c">
        <el-button type="primary" @click="clearCache">清空所有缓存</el-button>
        <div class="main-text">上次清除时间：{{lastClear}}</div>
      </div>
    </div>
  </div>
</div>
</template>

<script>
import {
  cacheClear,
  wipeCacheTime
} from '@/api/user'
export default {
  name: 'EmptyCache',
  components: {

  },
  computed: {

  },
  data() {
    return {
      lastClear: ''
    }
  },
  created() {
    this.$nextTick(() => {
      this.timeCreate()
    })
  },
  methods: {
    clearCache() {
      cacheClear().then((response) => {
        const res = response.data
        if (res.code === 1) {
          this.$message.success(res.message || '清空缓存成功')
          this.timeCreate()
        } else {
          this.$message.error(res.message || '清空缓存失败，请重试')
        }
      })
    },
    timeCreate() {
      wipeCacheTime().then((response) => {
        const res = response.data
        if (res.code === 1) {
          this.lastClear = res.data.createtime
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.empty-cache {
  font-size: 14px;

  .main {
    width: 100%;
    min-height: calc(100vh - 90px);
    border-radius: 4px;
    background: #ffffff;
  }

  .main-text {
    margin-top: 30px;
  }
}
</style>
